<script type="text/javascript">
function cariLayanan(){
	var id_ppk=$('#nama_ppk').val();
	popupCari('module/mod_klaim_ina/js/popup_inacbg.php?id_ppk='+id_ppk);
}

function hapusIna(obj){	
	 if (confirm('Apakah data akan dihapus ?')) {
  		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
		kalkulasi_layanan();
	}
}

function kalkulasi_layanan(){
	
	
	var jumlah_invoice=0;
	var jumlah_invoice_awal=0;
	jumlah_invoice=hitung_total_invoice_layanan();
	jumlah_invoice_awal=hitung_total_invoice_layanan_awal();
	var selisih_lab=jumlah_invoice_awal-jumlah_invoice;
	//alert('jumlah invoice '+jumlah_invoice);
	$('#total_ina').val(jumlah_invoice);
	$('#target_total_ina').html(number_format(jumlah_invoice, 0, ',','.'));
	$('#total_ina_awal').val(jumlah_invoice_awal);
	$('#target_total_ina_awal').html(number_format(jumlah_invoice_awal, 0, ',','.'));
	$('#target_selisih_ina').html(number_format(selisih_lab, 0, ',','.'));
	$('#selisih_ina').val(selisih_lab);
	hitung_semua_klaim();
}
function hitung_total_invoice_layanan_awal(){
	//alert('kocor');
		var frm=document.forms['form_klaim'];
		var harga_brg=frm.elements['harga_ina_awal[]'];
		//alert(harga_brg+' dan '+jml_pesanan);
		if(harga_brg==undefined){
			return 0;
		}
		n=harga_brg.length;
		var total=0;
		var sub_total=0
		if(n>1){
			for(var i=0;i<n;i++){
				sub_total=parseFloat(harga_brg[i].value);
				total+=sub_total;
			}
		}else{
			sub_total=parseFloat(harga_brg.value);
			total+=sub_total;
		}
		//alert(total);
		return total;
}

function hitung_total_invoice_layanan(){
	//alert('kocor');
		var frm=document.forms['form_klaim'];
		var harga_brg=frm.elements['harga_ina[]'];
		//alert(harga_brg+' dan '+jml_pesanan);
		if(harga_brg==undefined){
			return 0;
		}
		n=harga_brg.length;
		var total=0;
		var sub_total=0
		if(n>1){
			for(var i=0;i<n;i++){
				sub_total=parseFloat(harga_brg[i].value);
				total+=sub_total;
			}
		}else{
			sub_total=parseFloat(harga_brg.value);
			total+=sub_total;
		}
		//alert(total);
		return total;
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2"><table class="tabel" width="90%">
           <tr>
             <th scope="col">Nama Ina CBG </th>
             <th scope="col">Harga Ditanggung </th>
             <th scope="col">Harga Diminta </th>
             <th scope="col">&nbsp;</th>
           </tr>
			<tbody id="tbody_list_layanan">
			<?php
			$sql_layanan="select a.kode_inacbg, b.deskripsi,a.tarif,a.tarif_ditanggung from 
						klaim_inacbg a inner join master_inacbg b on a.kode_inacbg=b.kode_inacbg 
					 where a.id_klaim='".$id_klaim."'";
				//echo $sql_layanan;
			$qry_layanan=mysql_query($sql_layanan);
			$num_layanan=mysql_num_rows($qry_layanan);
			//echo 'num hasil '.$num_obat;
			$no=1;
			$total_tarif=0;
			$total_tarif_tanggung=0;
			if(!empty($id_klaim)&& $num_layanan>0){
				while($hasil_layanan=mysql_fetch_array($qry_layanan)){
			?>
			<tr>
			<td><?php echo $hasil_layanan['deskripsi']; ?><input type="hidden" name="id_ina[]"  value="<?php echo $hasil_layanan['kode_inacbg']; ?>"></td>
			<td><?php echo $hasil_layanan['tarif']; ?></td>
			<td>
			<input type="text" size="10" name="harga_ina[]" id="harga_ina_<?php echo $no;?>" value="<?php echo $hasil_layanan['tarif_ditanggung']; ?>"><input type="hidden" size="5" name="harga_ina_awal[]" id="harga_ina_awal_<?php echo $no;?>" value="<?php echo $hasil_layanan['tarif']; ?>">
			</td>
			<td><a href="javascript:void(null)" title="Hapus" onclick="hapusIna(this)"><img src="asset/images/button-delete.gif" alt="Hapus" border=0 /></a></td>
			</tr>
			<?php 
			$total_tarif+=$hasil_layanan['tarif'];
				$total_tarif_tanggung+=$hasil_layanan['tarif_ditanggung'];
				$no++;
			}
			$selisih=$total_tarif-$total_tarif_tanggung;
				$count_layanan=$num_layanan+1;
			}else{
				$count_layanan=1;
			}
			?>
		   </tbody>
</table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
       <td><a href="javascript:void(0)" title="Tambah" onclick="cariLayanan()"><img src="asset/images/button-add.gif" alt="Tambah" border=0 /></a></td>
       <td><input type="hidden" id="count_layanan" value="<?php echo $count_layanan; ?>" /></td>
  </tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Sub Total </td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td><div id="target_total_ina_awal" style="font-weight:bold;"><?php echo isset($total_tarif)?number_format($total_tarif,0,",","."):0;?></div>
	<input type="hidden" id="total_ina_awal" value="<?php echo isset($total_tarif)?$total_tarif:0;?>"  />	</td>
  </tr>
  <tr>
  <tr>
    <td>Sub Total Ditanggung</td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td><div id="target_total_ina" style="font-weight:bold;"><?php echo isset($total_tarif_tanggung)?number_format($total_tarif_tanggung,0,",","."):0;?></div>
	<input type="hidden" id="total_ina" value="<?php echo isset($total_tarif_tanggung)?$total_tarif_tanggung:0;?>" /></td>
  </tr>
  <tr>
    <td>Selisih</td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td><div id="target_selisih_ina" style="font-weight:bold;"><?php echo isset($selisih)?number_format($selisih,0,",","."):0;?></div>
	<input type="hidden" id="selisih_ina" value="<?php echo isset($selisih)?$selisih:0;?>" />
	</td>
  </tr>
</table>


